package com.pluginsacceptor.plugin.formula.datetime;

import java.util.Observable;
import java.util.Observer;

import javax.swing.JComponent;

import org.apache.log4j.Logger;

import com.pluginsacceptor.api.Activator;
import com.pluginsacceptor.plugin.formula.MathsTrigo.support.DataListener;
import com.pluginsacceptor.plugin.formula.MathsTrigo.support.DataSender;

public class DateTimeActivator implements Activator {


	/** Logger */
	private static final Logger LOG = Logger.getLogger(DateTimeActivator.class);

    /** Creation of  Observable named DataListener*/
    private DataListener dataListener;
    /** */
    private DataSender dataSender;

    /** */
	private DateTime dateTime;

	@Override
	public JComponent activate(final String[] metadata) {
		LOG.info("Activation of plugin DateTime");
		System.out.println("Activation of plugin DateTime");
		this.dataListener = new DataListener();
		this.dataSender = new DataSender();
		return null;
	}

	/**
	 * Deactivates the MathsTrig plug-In
	 */
	@Override
	public boolean deactivate() {
		LOG.info("Deactivate DateTime plugin");
		System.out.println("Deactivated DateTime plugin");
		return true;
	}

	/**
	 * Adds an observer to the component
	 */
	@Override
	public void addObserver(final Observer observer) {
		LOG.info("Added observer");
		this.dataSender.addObserver(observer);
	}

	/**
	 * Gets an Observer
	 */
	@Override
	public Observer getObserver() {
		return new Observer () {
            @Override
            public void update(final Observable o, final Object arg) {
                dataListener.updateDate(arg);
            }
        };
	}


    @Override
    public JComponent getMenuItem() {
        return new DateTimeMenu(this.dataListener, this.dataSender);
    }

	@Override
	public Object save() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean load(final Object data) {
		// TODO Auto-generated method stub
		return false;
	}
}



